import {Pipe, PipeTransform} from '@angular/core';
import { DomSanitizer } from '@angular/platform-browser';

/**
 * 二手售后单状态
 * 0-已申请、1-待买家退货、2-退货超时、3-商品已寄出、4-到货待审核、5-退款中、6-售后成功、7-售后失败、8-已取消、9-退款失败
 * ----------------------------------------------------------------
 */
export const secondSaleAfterStatusArrs = [
  {value: 0, label: '已申请', color: '#FF6600'},
  {value: 1, label: '待买家退货', color: '#666666'},
  {value: 2, label: '退货超时', color: '#FF0000'},
  {value: 3, label: '商品已寄出', color: '#666666'},
  {value: 4, label: '到货待审核', color: '#FF0000'},
  {value: 5, label: '退款中', color: '#909399'},
  {value: 6, label: '售后成功', color: '#008000'},
  {value: 7, label: '售后失败', color: '#909399'},
  {value: 8, label: '已取消', color: '#909399'},
  {value: 9, label: '退款失败', color: '#909399'}
];

@Pipe({
  name: 'secondSaleAfterStatus'
})
export class SecondSaleAfterStatusPipe implements PipeTransform {
  transform(value: any, type?: string) {
    let tempObj: any = secondSaleAfterStatusArrs.find((item: any) => item.value === value);
    if (type && type === 'color') {
      return tempObj?.color || '#909399';
    } else {
      return tempObj?.label || '-';
    }
  }
}

/**
 * 售后方式 1-退货退款，2-维修，3-取消订单、4-仅退款、5-补货
 * ----------------------------------------------------------------
 */
export const secondSaleAfterModeArrs = [
  {value: 1, label: '退货退款', color: '#FF6600'},
  {value: 2, label: '维修', color: '#666666'},
  {value: 4, label: '仅退款', color: '#FF0000'}
];

@Pipe({
  name: 'secondSaleAfterMode'
})
export class SecondSaleAfterModePipe implements PipeTransform {
  transform(value: any, type?: string) {
    let tempObj: any = secondSaleAfterModeArrs.find((item: any) => item.value === value);
    if (type && type === 'color') {
      return tempObj?.color || '#909399';
    } else {
      return tempObj?.label || '-';
    }
  }
}

/**
 * 售后方式 0：未退款 1：等待中 2：退款成功 3：退款失败
 * ----------------------------------------------------------------
 */
export const secondRefundPriceArrs = [
  {value: 0, label: '未退款', color: '#FF6600'},
  {value: 1, label: '等待中', color: '#666666'},
  {value: 2, label: '退款成功', color: '#FF0000'},
  {value: 3, label: '退款失败', color: '#FF0000'}
];

@Pipe({
  name: 'secondRefundPrice'
})
export class SecondRefundPriceArrsPipe implements PipeTransform {
  transform(value: any, type?: string) {
    let tempObj: any = secondRefundPriceArrs.find((item: any) => item.value === value);
    return tempObj?.label || '-';
  }
}

// html
@Pipe({
  name: 'domHtml'
})
export class domHtmlPipe implements PipeTransform {
  constructor(private domSanitizer: DomSanitizer) {}

  transform(value: string) {
    return this.domSanitizer.bypassSecurityTrustHtml(value);
  }
}